package cn.com.lms.business.examRewrite.persistence.repository;

import cn.com.lms.business.examRewrite.persistence.entity.PaperExtraReWrite;
import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PaperExtraReWriteDao extends BaseRepository<PaperExtraReWrite,Long> {

    /**
     * 通过paper_id查出数据
     * @param id
     * @return
     */
    @Query(nativeQuery = true,value = "SELECT * FROM bnz_exam_paper_extra WHERE paper_id = ?1")
    PaperExtraReWrite getPaperExtra(Long id);

    /**
     * 更新paperExtraReWrite
     * @param id
     * @param paperTotalScore
     * @param paperTotalCount
     */
    @Query(nativeQuery = true,value = "UPDATE bnz_exam_paper_extra SET subject_count = :paperTotalCount ,paper_score = :paperTotalScore WHERE paper_id = :id")
    @Modifying
    void updataPaperExtraReWrite(@Param("id") Long id, @Param("paperTotalScore") Integer paperTotalScore, @Param("paperTotalCount") Integer paperTotalCount);

    /**
     * 通过paperId获取数据
     * @param id
     * @return
     */
    PaperExtraReWrite getPaperExtraReWriteByPaperId(Long id);

    /**
     * 通过PaperId获取数据
     * @param ids
     */
    @Query(nativeQuery = true,value = "DELETE FROM bnz_exam_paper_extra WHERE paper_id in (:ids)")
    @Modifying
    void deletePaperExtraReWriteByPaperId(@Param("ids") List<Long> ids);

}
